cmake_minimum_required(VERSION 3.18.1)

project("javahook")

enable_language(ASM)

include_directories(.)

add_subdirectory(shook EXCLUDE_FROM_ALL)
set(HOOKLIB shadowhook)
set(HOOKDEF -DUSE_SHOOK=1)

set(CMAKE_CXX_STANDARD 20)

if(${ANDROID_ABI} MATCHES   "arm64-v8a")
    set(EXSRC
        JavaHook/asm_support_arm64.S
        JavaHook/hook_trampoline_arm64.S
    )
elseif(${ANDROID_ABI} MATCHES   "armeabi-v7a")
    set(EXSRC
        JavaHook/asm_support_arm.S
        JavaHook/hook_trampoline_arm.S
    )
endif()

add_library(
    javahook

    SHARED

    javatweak.cpp
    ApiHook/ApiHook.cpp
    JavaHook/JavaHook.cpp
    JavaHook/HookTrampoline.cpp
    JavaHook/HookHelper.cpp
        ${EXSRC}
)

find_library(log-lib  log )
target_compile_definitions(javahook PRIVATE -DEXTERNALDEX=0 ${HOOKDEF} -DCONSTRUCTOR=1)

target_link_libraries(
    javahook
    ${HOOKLIB}
    ${log-lib}
)
